<?php
$pharmacy_id = $_SESSION['acc_id'];

$product_name = $product_type = $country_id = $price = $laboratory = $product_description = "";
$count_arry =  $price_array = $labor_array = $pid_array = array();
$sql = "SELECT tblproduct.*,tblproduct_in_pharmacy.* FROM tblproduct,tblproduct_in_pharmacy WHERE tblproduct.id=$id AND tblproduct.id = tblproduct_in_pharmacy.product_id AND tblproduct_in_pharmacy.pharmacy_id = $pharmacy_id";
$result = mysql_query($sql);
$result1 = mysql_query($sql);
while($row_c = mysql_fetch_assoc($result1)){
		$count_arry[] = $row_c['country_id'];	
		$price_array[] = $row_c['price'];
		$labor_array[] = $row_c['laboratory'];
		$pid_array[] = $row_c['pid'];
	}
$row = mysql_fetch_assoc($result);
if(dbNumRows($result)){
extract($row);
}
?>
<script src='jquery.js' type="text/javascript"></script>
<script src='documentation.js' type="text/javascript"></script>
<script src='jquery.MultiFile.js' type="text/javascript" language="javascript"></script>
<script type="text/javascript" src="<?php echo W_ROOT;?>/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="<?php echo W_ROOT;?>/jscripts/initialeditor.js"></script>
<script type="text/javascript" src="<?php echo W_ROOT;?>/templates/javascripts/jquery.foundation.tabs.js"></script>
<script type="text/javascript" src="<?php echo W_ROOT;?>/templates/javascripts/foundation.min.js"></script>
<script type="text/javascript" src="<?php echo W_ROOT;?>/templates/javascripts/app.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
$('.delcount').click(function(){
	var id = $(this).attr('id');
	
	if($(".selectCon").length>1){
		$.ajax({
				type: "GET",
				url: "process.php",
				data: "action=deletet_count&pid=" + id,
				success: function(message){
					$('.'+id).remove();
				}
		});
	}else{
		alert('You cannot delete the last one!');
		$('.delcount').addClass('displayNo');
	}
	
});
});
</script>
<style type="text/css">
#backgroundPopup{  
display:none;  
position:fixed;  
_position:absolute; /* hack for internet explorer 6*/  
height:100%;  
width:100%;  
top:0;  
left:0;  
background:#000000;  
border:1px solid #cecece;  
z-index:1;  
}  
#popuptext{  
display:none;  
position:fixed;  
_position:absolute; /* hack for internet explorer 6*/  
height:400px;  
width:650px;  
background:#FFFFFF;  
border:2px solid #cecece;  
z-index:2;  
padding:12px;  
font-size:13px;  
} 
#popupCategory{  
display:none;  
position:fixed;  
_position:absolute; /* hack for internet explorer 6*/  
height:400px;  
width:635px;  
background:#FFFFFF;  
border:2px solid #cecece;  
z-index:2;  
padding:12px; 
overflow:scroll;
overflow-x: hidden; 
} 
#popuptextClose{
font-size:14px;
line-height:14px;
right:6px;
top:4px;
position:absolute;
color:#6fa5fd;
font-weight:700;
display:block;
cursor:pointer;
}
#popupcateClose{
font-size:14px;
line-height:14px;
right:6px;
top:4px;
position:absolute;
color:#6fa5fd;
font-weight:700;
display:block;
cursor:pointer;
}
.check_bok
{
    padding:2px;
    margin:3px;
    cursor:pointer;
    color:#ffffff;
    float: left;
    border:#aaa solid 1px;
}
.ch_red
{
   background: red;
}
</style>
<script src="popup.js" type="text/javascript"></script>
<script language="javascript">  
    function fncCreateElement(){
      
    var mySpan = document.getElementById('mySpan');  
      
    var myLine = document.getElementById('hdnLine');  
    myLine.value++;  
      
    var myElement1 = document.createElement('input');  
    myElement1.setAttribute('type',"text");  
    myElement1.setAttribute('name',"txtsizename[]");  
    myElement1.setAttribute('style',"width:40px; float: left;margin-right:3px;height: 23px"); 
    myElement1.setAttribute('id',"txt"+myLine.value);  
    mySpan.appendChild(myElement1);  
      
    // Create <br>  
    var myElement2 = document.createElement('<br>');  
    myElement2.setAttribute('id',"br"+myLine.value);  
    mySpan.appendChild(myElement2);  
      
    }  
      
    function fncDeleteElement(){  
      
    var mySpan = document.getElementById('mySpan');  
      
    var myLine = document.getElementById('hdnLine');  
      
    if(myLine.value > 1 )  
    {  
      
    // Remove Text  
    var deleteEle = document.getElementById("txt"+myLine.value);  
    mySpan.removeChild(deleteEle);  
      
    // Remove <br>  
    var deleteBr = document.getElementById("br"+myLine.value);  
    mySpan.removeChild(deleteBr);  
      
    myLine.value--;  
    }  
    }  
    </script>
<dl class="tabs">
  <dd class="active"><a href="#detail"><!--Edit Product--><?php echo $lang['EDITPRODUCTT'] ;?></a></dd>
  <dd><a href="#category"><!--Categories--><?php echo $lang['CATEGORIES'];?></a></dd>
</dl>

					<div  class="four columns offset-by-eight">   
                        <div class="widget"> 
                            <input class="btn btn-warning" type="button" value="<?php echo $lang['CANCEL'];?>" onclick="window.location.href='index.php'" />               
                            <input class="btn btn-primary" type="button" name="btnsubmit" value="<?php echo $lang['PUBLISH'];?>" onclick="checkSellerform();" />&nbsp;&nbsp;&nbsp;
                            <input type="hidden" name="hidid" value="<?php echo $id;?>" />
                        </div>
                    </div>
                    
<div class="row">
    <div class="twelve columns">
        <ul class="tabs-content">
                <!--detail section-->
              <li class="active" id="detailTab">
                <label><!--Product Name--> <?php echo $lang['PRO_NAME'] ;?>:</label>
                <input type="text" style="width:99%;"  name="new_proname" value="<?php echo stripslashes($product_name);?>" />
                
                
                <!-- sidebar -->
    <div class="twelve columns">
        <div style="" class="lside">
            <div class="row">
                <div class="twelve columns">  
                
                    <!--<div class="twelve columns">   
                        <div class="widget">                
                            <input class="btn btn-primary" type="button" name="btnsubmit" value="<?php echo $lang['PUBLISH'];?>" onclick="checkSellerform();" />&nbsp;&nbsp;&nbsp;
                            <input class="btn btn-warning" type="button" value="<?php echo $lang['CANCEL'];?>" onclick="window.location.href='index.php'" />
                            <input type="hidden" name="hidid" value="<?php echo $id;?>" />
                        </div>
                    </div>-->
                 
                    <div class="widget">         
                        <?php 
                            $color_array = array();
                            $brand_name_array = array();
                            $size_id_array = array();
                             $str_color=mysql_query("SELECT *FROM tbl_color");
                             $ch_color=mysql_query("SELECT *FROM tbl_color_size WHERE pid=$id"); 
                            while($rowss = mysql_fetch_array($ch_color)){
                 
                                   $color_array[]=$rowss['color_id'];
                                   $brand_name_array[]=$rowss['brand_name'];
                                   $size_id_array[]=$rowss['size_id'];
                              }     
                                           
                        ?>
                        <label><!--Color--><?php echo  $lang['COLOR'];?>:</label>
                        <?php while($rows_color=mysql_fetch_array($str_color)){ 
                             $checkedcolor = (in_array($rows_color['color_id'],$color_array))?' checked="checked"':'';
                            ?>
                        <div  class="check_bok" style="background-color:<?php echo $rows_color['color_name'];?>"> <input <?php echo $checkedcolor;?> type="checkbox" name="txtcheckboxProduct[]" value="<?php echo $rows_color['color_id']?>" /></div>      
                        <?php } ?>
                        <div class="clear"></div>
                    </div>
                </div>
                
                
                
                <div class="twelve columns">
                    <div class="widget">
                        <label><!--Size--> <?php echo $lang['SIZE'];?>:</label>                                
                        <div id="mySpan" style="float:left;">
                        <?php
                        if($size_id_array)
                        {                             
                            foreach ($size_id_array as $key => $value)
                            {
                                if($value!=0)
                                {
                                ?>
                                    <input type="text" name="txtsizename[]" style="width:40px; float: left;margin-right:3px;height: 23px" value="<?php echo $value;?>" />
                                <?php
                                }
                            }
                        }
                        else
                        {
                            echo '<input type="text" name="txtsizename[]" style="width:40px; float: left;margin-right:3px;height: 23px"/>';
                        }    
                        ?>
                        </div>  
                        <input id="hdnLine" name="hdnLine" type="hidden" value="1" /> 
                        <input class="btn" type="button" value="+" onClick="JavaScript:fncCreateElement();" id="adin" />
                        <input class="btn" type="button" name="btnDelete" value="-" onClick="JavaScript:fncDeleteElement();" id="adin"/>
                    </div>
                </div>
                
                
                
                
                
                <?php
                    foreach($count_arry as $key => $value)
                   	{
                  		$country_id = $value;
                  		$price = $price_array[$key];
                  		$laboratory = $labor_array[$key];                                
                  		$pid = $pid_array[$key];
                            	?> 
                <div class="twelve columns">    
                    <div class="row">
                    <div class="three columns">
                            <label><!--Brand name--><?php echo $lang['BRAND_NAME'];?> : </label> 
                        <?php                        
							$b_get = mysql_query("SELECT * FROM tbl_brand"); 
						?>
						<select name="selectType" id="selectbox">
							<option><!--select Brand--><?php echo $lang['SEL_BRAND'];?></option>
							<?php
                             
							while ($brand = mysql_fetch_assoc($b_get))
								{
								    $checkedbrand = (in_array($brand['brand_name'],$brand_name_array))?' selected="selected"':'';
								?>    
								<option <?php echo $checkedbrand;?> value="<?php echo $brand['brand_name'];?>"><?php echo $brand['brand_name'];?></option>
								<?php
								}
							?>
				        </select>
                    </div>
                    
                    
                        <div class="three columns">
                            <label><!--Country--><?php echo $lang['SHIP_COUNTRY'];?> : </label>                             
                                <!--Made In <a style="color:#F00; cursor:pointer;" id="<?php echo $pid?>" class="delcount"><strong>[x]</strong></a>-->
                            
                                <select name="selectCoun[]" id="selectbox" class="selectCon">
                                <option value="0">select country</option>
                                <?php
                            	$sql_coun = "SELECT id,country_name FROM tblcountries";
                            	$result_coun = mysql_query($sql_coun);
                            	while($row_coun = dbFetchAssoc($result_coun)){
                            	?>
                                <option value="<?php echo $row_coun['id']?>" <?php echo($row_coun['id']==$country_id)?' selected="selected"':''?>><?php echo $row_coun['country_name']?></option>
                                <?php	
                            	}
                            	?>
                                </select>
                        </div>
                        <div class="three columns txtpricediv">
                                   <!-- Price($) --><?php echo  $lang['PRICE'];?>: <br />
                                    <input type="text" name="price[]" style="width:80px;" value="<?php echo $price;?>" class="txtprice" />
                        </div>
                         <div class="three columns txtpricediv">
                                   <!-- Regular Price($)--><?php echo  $lang['REG_PRICE'];?> :<br /> 
                                   <input type="text" name="price_regular[]" style="width:80px;" value="<?php echo $regular_price;?>" class="txtprice_reg" />                                   
                         </div>
                         <input type="hidden" name="hidpid[]" value="<?php echo $pid;?>" />                         
                    </div>
                </div>  
                <?php
                  }
                ?> 
                
                
                
                <div class="twelve columns">
                    <div class="widget">
                        <label><!--Images --><?php echo $lang['IMG'];?>: </label> 
                        <input type="file" class="multi" name="imagefile[]" size="35"/>
                         <div class="imageitem"> 
                        	<?php
                        	$sql_img = "SELECT * FROM tblimage WHERE product_id =".$id;
                        	$result_img = mysql_query($sql_img);
                        	if(dbNumRows($result_img)){
                        	?>
                           <?php
                           	while( $row_img = mysql_fetch_assoc($result_img)){
                        		if($row_img['product_id'] !=""){
                           ?>
                           <div style="float:left;" class="div<?php echo $row_img['id'];?>">
                           <input name="DelImage[]" type="checkbox" value="<?php echo $row_img['id'];?>" id="checkbox<?php echo $row_img['id'];?>" class="regular-checkbox" />                           
                            <label for="checkbox<?php echo $row_img['id'];?>"><img src="<?php echo W_ROOT;?>/company/product/uploads/<?php echo $row_img['thumbnail'];?>" class="border" width="80" height="80" /></label>                            
                            </div>
                            <?php
                        		}//end if
                        	}//end if
                        	}//end while
                        	?>
                        </div>
                    </div>
                </div>            
            
            </div>
        </div>               
    </div>
    <!-- end sidebar -->
                
                <label><!--Short Description--><?php echo $lang['SHORT_DESCRIP'];?> : </label>
                <textarea name="shot_disc" id="shot_disc" style="height:100px;"><?php echo stripslashes($short_desciption);?></textarea>
                <label><!--Long description--> <?php echo $lang['LONG_DESCRIP'];?>:</label> 
                <textarea name="txtdesc" id="txtdesc" style="height:100px;"><?php echo stripslashes($product_description);?></textarea>
                <!--end detail section-->
              </li>
              
              <!-- category section -->
              <li id="categoryTab">
                <?php
                	include('category.php');
                ?> 
              </li>
              <!-- end category section -->
        </ul>
    </div>  
       
    
</div>  